Renderer transformation refactor - #165
Conversation
494045a to
e357f84
Compare
|
Best of luck Dext; you're gonna need it o7 |
| std::array<uint16_t, MaxMvlIndices> MvlIndices; | ||
| int MvlIndicesCount; | ||
| std::vector<VertexBufferSprites> MvlVertices; | ||
| std::vector<uint16_t> MvlIndices; |
There was a problem hiding this comment.
Have you tested if there's any perf hit to using vector instead of array here?
There was a problem hiding this comment.
There is, going from ~200fps to ~80fps in debug mode with three characters on screen, but frankly we should be doing these transformations in the vertex shader anyway...
Lemme know if I should look into that in this PR already or if this can wait until the full-scale refactor
There was a problem hiding this comment.
We should leave it as an array for now then and move the transformation into the vertex shader later
There was a problem hiding this comment.
Oh wait I think I misunderstood your comment. I think most of the performance hit came from the matrix multiplication; I doubt the switch to vector really did anything noticable. Could profile a little more closely later
There was a problem hiding this comment.
Ah okay, you should also probably do profiling in optimized build, matrix multiplication will probably be a lot faster there. There's also probably some SIMD that gets done by default too
There was a problem hiding this comment.
Yeah okay, I did some more profiling and it looks to me like the vectorization doesn't really seem to be an impact at all (as in, the loading of the vertices is so fast visual studio can't even process anything meaningful).
I've also checked the matrix multiplications in in release mode, and the fps in the cclcc system menu (which thus far is the worst case scenario I could find) goes from ~800fps on master down to ~340fps, which is a perf hit, but it's still 340fps, and again should be moved to the vertex shader anyway
There was a problem hiding this comment.
Yeah we should just move it to the vertex shader. I'd like to see what the numbers are on a worse device like a steam deck though, I assume your computer is probably pretty beefy, so if the perf is a 60% hit on a crappy device it might be a lot worse
| NegativeDelusionSprite, glm::vec2{topLeftX, -109.0f}, | ||
| glm::vec2{424.0f, 557.0f}, | ||
| {1.0f, 1.0f, 1.0f, (float)spinAlpha / 256.0f}, {1, 1}, spinAngle); | ||
| const glm::vec2 topLeft = { |
There was a problem hiding this comment.
These probably shouldn't be named topLeft or center and more like offset or something, I can't remember if these names were actually accurate or not or something i just put in.
|
Vulkan seems to be artifacting a lot, it's especially noticable on chlcc, but I'm not sure if it was always like that |
Yeah, Vulkan is very jittery on master too, so I tried not to make things any worse, but also didn't really make an effort to make it much better either. Would need to do a deep dive into learning Vulkan for that at some point |
7268747 to
a10c44a
Compare
75e60b8 to
89de8c2
Compare
| Renderer->DrawVertices(SystemMenuBG.Sheet, SpriteGridVertices, | ||
| DisplayGridVertices, 21, 11); | ||
| const CornersQuad bgDisp = | ||
| CornersQuad(BGDispOffsetTopLeft, BGDispOffsetBottomLeft, |
| bool isInverted, bool useMaskAlpha) override; | ||
|
|
||
| void DrawVertices(const SpriteSheet& sheet, | ||
| std::optional<const SpriteSheet> mask, |
There was a problem hiding this comment.
This will always be a copy, for a const object it would make more sense to get a reference somehow, pointer or maybe a typedefed optional<reference_wrapper>?
There was a problem hiding this comment.
You could also just do default constructible spritesheet and validate it using texture id or something
There was a problem hiding this comment.
I'm thinking it might be better to just make it a pointer instead for consistency with everything else (also the draw text functions are already nullable pointers)
|
|
||
| // ShaderCompiler compiler | ||
| ShaderCompiler* Shaders; | ||
| std::shared_ptr<ShaderCompiler> Shaders; |
There was a problem hiding this comment.
The lifetime of Shaders isn't unknown or ambiguous, so a shared_ptr isn't necessary here. Scene3D is the only user and it's a member of renderer, so its lifetime will be tied to renderer. Try to avoid shared_ptr unless necessary cuz it does have a perf hit with reference counting + atomic operations.
There was a problem hiding this comment.
I'd say just stick to unique_ptr (owner) + ref/raw ptr(users) as a general pattern, but here i think you might be able to just store the value itself and pass references to children
| void QuadSetPosition3DRotated(RectF const& transformedQuad, float depth, | ||
| glm::vec2 vanishingPoint, bool stayInScreen, | ||
| glm::quat rot, uintptr_t positions, int stride); | ||
| std::unique_ptr<SpriteShader> SpriteShaderProgram; |
There was a problem hiding this comment.
These are all different types and can just be stored as values
There was a problem hiding this comment.
Use optional if late initialization is needed
| const GLint TexturesLocation; | ||
| }; | ||
|
|
||
| struct SpriteInvertedUniforms { |
There was a problem hiding this comment.
Not strictly, but I thought it useful to give it its own struct anyway in case SpriteInverted ever has to divert from Sprite
| struct MaskedSpriteNoAlphaUniforms { | ||
| bool operator==(const MaskedSpriteNoAlphaUniforms& other) const = default; | ||
|
|
||
| glm::mat4 Projection = glm::mat4(); |
There was a problem hiding this comment.
just do glm::mat4 Projection{}
|
|
||
| const size_t indexOffset = IndexBuffer.size(); | ||
| IndexBuffer.resize(IndexBuffer.size() + indices.size()); | ||
| std::transform( |
There was a problem hiding this comment.
you can avoid the resize with back_inserter on IndexBuffer.end()
There was a problem hiding this comment.
Won't that continuously push back all the elements, possibly expanding multiple times, instead of resizing just once?
There was a problem hiding this comment.
Yeah you can reserve in that case for the allocation, using back_inserter lets you avoid the default construction
| static constexpr size_t TextureUnitCount = 15; | ||
| static constexpr std::array<GLint, TextureUnitCount> Textures = { | ||
| 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; | ||
| std::array<std::unique_ptr<TextureUnit>, TextureUnitCount> TextureUnits; |
There was a problem hiding this comment.
Does this need to be unique_ptrs? You might be able to store TextureUnits or optional TextureUnits instead
There was a problem hiding this comment.
TextureUnits don't have a default constructor, so I needed late initialization. Optional is possible tho
| void Reserve() { Info->Flushed = false; } | ||
|
|
||
| private: | ||
| const GLuint Unit; |
There was a problem hiding this comment.
If it's meant to be or copyable, maybe don't have member variables as const since those kill the assignment operators
| // Add outline to the front of the buffers | ||
| vertices.insert(vertices.end(), vertices.begin(), vertices.end()); | ||
|
|
||
| indices.resize(indexCount * 2); |
a47766e to
b6bcc1e
Compare
|
(Fyi I only rebased, so you'll only have to check the five added commits) |
b6bcc1e to
b6ff901
Compare
1d16a0e to
27e9e62
Compare
Fix code style issues with clang_format Size and position correction Proper .gitignore C;H LCC SystemMenu Cleanup almost perfect CHLCC SystemMenu Added MenuLoopDuration to lua config files Cleanup Fixed error after Renderer transformation refactor (pull request CommitteeOfZero#165) remove comments
Fix code style issues with clang_format Size and position correction Proper .gitignore C;H LCC SystemMenu Cleanup almost perfect CHLCC SystemMenu Added MenuLoopDuration to lua config files Cleanup Fixed error after Renderer transformation refactor (pull request CommitteeOfZero#165) remove comments
A refactor of the renderer to make more use of generic transformation matrices instead of a myriad purpose-built overloads.
Also adds useful functions for generating these transformation matrices, monadically transforming
RectFs andCornerQuads, and reduces code duplication within and across the renderer implementations.A number of internal renderer components have also been overhauled to become managed and make use of more modern C++.
Implements
DrawMaskedSpritefor both DirectX9 and Vulkan.Should (obviously) not visually change anything for the worse.